package com.example.module.system.service.sendrecord;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.framework.common.util.EncryptUtils;
import com.example.framework.common.util.json.JsonUtils;
import com.example.module.system.dal.dataobject.MessageSendRecordDO;
import com.example.module.system.dal.mysql.sendrecord.MessageSendRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class MessageSendRecordServiceImpl extends ServiceImpl<MessageSendRecordMapper, MessageSendRecordDO> implements MessageSendRecordService {

    @Value("${encrypt.aes.secret}")
    private String aesSecret;

    @Override
    public void saveResult(Integer msgType, Object sendResult, String receiver, String content) {
        MessageSendRecordDO messageSendRecordDO = MessageSendRecordDO.builder()
                .msgType(msgType)
                .receiver(EncryptUtils.AesEncrypt(receiver, aesSecret))
                .content(content)
                .sendResult(JsonUtils.toJsonString(sendResult))
                .build();
        this.save(messageSendRecordDO);
    }
}
